const fs = require('fs');
const path = require('path');

// 修复index.html中的路径
const htmlPath = path.join(__dirname, '../dist/index.html');
let html = fs.readFileSync(htmlPath, 'utf8');
html = html.replace(/\/assets\//g, './assets/');
fs.writeFileSync(htmlPath, html);

// 修复manifest.json中的路径
const manifestPath = path.join(__dirname, '../dist/manifest.json'); 
let manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
if (manifest.background?.service_worker) {
  manifest.background.service_worker = manifest.background.service_worker.replace(/^src\//, './');
}
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));

console.log('Fixed paths in dist files');